﻿using System;
using DevExpress.XtraEditors;

namespace DataCopy
{
    public partial class frmAyarlar : XtraForm
    {
        public frmAyarlar()
        {
            InitializeComponent();
        }

        private void frmAyarlar_Load(object sender, EventArgs e)
        {
            for (int i = 1; i < vGridControl1.Rows.Count; i++)
            {
                if (!string.IsNullOrEmpty(vGridControl1.Rows[i].Properties.FieldName))
                {
                    switch (vGridControl1.Rows[i].Properties.UnboundType)
                    {
                        case DevExpress.Data.UnboundColumnType.Boolean:
                            vGridControl1.Rows[i].Properties.Value = Convert.ToBoolean(Program.Session[(Settings)Enum.Parse(typeof(Settings), vGridControl1.Rows[i].Properties.FieldName)]);
                            break;
                        case DevExpress.Data.UnboundColumnType.DateTime:
                            vGridControl1.Rows[i].Properties.Value = Convert.ToDateTime(Program.Session[(Settings)Enum.Parse(typeof(Settings), vGridControl1.Rows[i].Properties.FieldName)]);
                            break;
                        case DevExpress.Data.UnboundColumnType.Decimal:
                            vGridControl1.Rows[i].Properties.Value = Convert.ToDecimal(Program.Session[(Settings)Enum.Parse(typeof(Settings), vGridControl1.Rows[i].Properties.FieldName)]);
                            break;
                        case DevExpress.Data.UnboundColumnType.Integer:
                            vGridControl1.Rows[i].Properties.Value = Convert.ToInt32(Program.Session[(Settings)Enum.Parse(typeof(Settings), vGridControl1.Rows[i].Properties.FieldName)]);
                            break;
                        case DevExpress.Data.UnboundColumnType.String:
                            vGridControl1.Rows[i].Properties.Value = Convert.ToString(Program.Session[(Settings)Enum.Parse(typeof(Settings), vGridControl1.Rows[i].Properties.FieldName)]);
                            break;
                        default:
                            vGridControl1.Rows[i].Properties.Value = Program.Session[(Settings)Enum.Parse(typeof(Settings), vGridControl1.Rows[i].Properties.FieldName)];
                            break;
                    }
                }
            }
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            for (int i = 1; i < vGridControl1.Rows.Count; i++)
            {
                if (vGridControl1.Rows[i].Properties.Value != null)
                    Program.Session[((Settings)Enum.Parse(typeof(Settings), vGridControl1.Rows[i].Properties.FieldName))] = vGridControl1.Rows[i].Properties.Value.ToString();
            }
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }
    }
}
